package io.renren.modules.generator.controller;

import java.util.*;

import io.renren.datasource.annotation.DataSource;
import io.renren.modules.generator.entity.GongxuDto;
import io.renren.modules.generator.entity.OrderDto;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.JitaiEntity;
import io.renren.modules.generator.service.JitaiService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 机台维护
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-07-22 14:08:59
 */
@RestController
@RequestMapping("generator/jitai")
public class JitaiController {
    @Autowired
    private JitaiService jitaiService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:jitai:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = jitaiService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:jitai:info")
    public R info(@PathVariable("id") Integer id){
		JitaiEntity jitai = jitaiService.getById(id);

        return R.ok().put("jitai", jitai);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:jitai:save")
    public R save(@RequestBody JitaiEntity jitai){
		jitaiService.save(jitai);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:jitai:update")
    public R update(@RequestBody JitaiEntity jitai){
		jitaiService.updateById(jitai);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:jitai:delete")
    public R delete(@RequestBody Integer[] ids){
		jitaiService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @DataSource(value = "slave1")
    @RequestMapping("/order")
    public R order(@RequestParam Map<String, Object> params){
        List<OrderDto> test = jitaiService.test( params);

        return R.ok().put ("list",test);
    }

    @DataSource(value = "slave1")
    @RequestMapping("/updateSort")
    public R updateSort(Integer id,Integer sort){
        jitaiService.updateSort(id,sort);
        return R.ok();
    }

    @DataSource(value = "slave1")
    @RequestMapping("/kaigong")
    public R kaigong(Integer id,String kaigong,Date startDate,Date finishDate){
        jitaiService.kaigong(id,kaigong, startDate, finishDate);
        return R.ok();
    }

    @DataSource(value = "slave1")
    @RequestMapping("/gongxu")
    public R gongxu(@RequestParam Map<String, Object> params){
        List<GongxuDto> gongxu = jitaiService.gongxu(params);
        List nullList = new ArrayList();
        nullList.add(null);
        gongxu.removeAll(nullList);
        return R.ok().put ("list",gongxu);
    }

}
